<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <script src="../js/vue-2.6.js"></script>
    <script src="../plugins/elementui/eui-2.13.js"></script>
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/elementui/eui-index.css">


    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/style.css">
    <script src="../js/echarts.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>统计分析<small>会员数量</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>会员数量</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <template>
            <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
                <el-tab-pane label="会员数量-日期" name="first">
                    <div class="block" align="center" style="width: 80%">
                        <el-button type="text"><b style="font-size: larger">日期区间:</b></el-button>
                        &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                        <el-date-picker
                                v-model="value2"
                                type="monthrange"
                                align="right"
                                unlink-panels
                                range-separator="至"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :picker-options="pickerOptions"
                                @change="loadMemberReport"
                                value-format="yyyy-MM-dd">
                        </el-date-picker>
                    </div>
                </el-tab-pane>
                </el-tab-pane>
            </el-tabs>
        </template>
        <div class="box">
            <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
            <div id="chart1" v-show="showChart1" style="height:600px;"></div>
            <div id="chart2" v-show="showChart2" style="height:600px;"></div>
            <div id="chart3" v-show="showChart3" style="height:600px;"></div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<!--    <script src="../js/vue.js"></script>-->
<!--    <script src="../js/axios-0.18.0.js"></script>-->

<script>
    new Vue({
        el: "#app",
        data: {
            pickerOptions: {
                shortcuts: [{
                    text: '本月',
                    onClick(picker) {
                        picker.$emit('pick', [new Date(), new Date()]);
                    }
                }, {
                    text: '今年至今',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date(new Date().getFullYear(), 0);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近六个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setMonth(start.getMonth() - 6);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            value2: '',
            activeName: 'first',
            showChart1:'true',
            showChart2:'false',
            showChart3:'false',

        },
        created() {
            this.loadMemberReport();
        },
        methods: {
            handleClick(tab, event) {
                if(tab.name=='first'){
                    this.showChart1=true;
                    this.showChart2=false;
                    this.showChart3=false;
                    this.loadMemberReport();
                }

            },
            loadMemberReport() {
                axios.post("/report/memberReport.do?dateCondition="+this.value2).then((res) => {
                    let data = res.data;
                    if (data.flag) {
                        this.initReport(data.data.months, data.data.memberCounts);
                    } else {
                        this.$message.error(data.message);
                    }
                })
            },
            initReport(months, memberCounts) {
                // 基于准备好的dom，初始化echarts实例
                let myChart = echarts.init(document.getElementById('chart1'));

                // 指定图表的配置项和数据
                let option = {
                    title: {
                        text: '会员数量'
                    },
                    tooltip: {},
                    legend: {
                        data: ['会员数量']
                    },
                    xAxis: {
                        data: months
                    },
                    yAxis: {},
                    series: [{
                        name: '会员数量',
                        type: 'line',
                        data: memberCounts
                    }]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            },

            initReportGender(legendData,seriesData){
                // 基于准备好的dom，初始化echarts实例
                let myChart = echarts.init(document.getElementById('chart2'));

                let  option = {
                    title: {
                        text: '会员数量-性别',
                        subtext: '',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: legendData,
                    },
                    series: [
                        {
                            name: '会员数量-性别',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            data: seriesData,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            },
            loadMemberReportAge(){
                axios.post("/report/memberReportAge.do").then((res) => {
                    let data = res.data;
                    if (data.flag) {
                        this.initReportAge(data.data.legendData, data.data.seriesData);
                    } else {
                        this.$message.error(data.message);
                    }
                })
            },
            initReportAge(legendData,seriesData){
                // 基于准备好的dom，初始化echarts实例
                let myChart = echarts.init(document.getElementById('chart3'));
                let  option = {
                    title: {
                        text: '会员数量-年龄分段',
                        subtext: '',
                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: legendData,
                    },
                    series: [
                        {
                            name: '会员数量-性别',
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            data: seriesData,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            }
        }
    })
</script>

</html>
